@extends('shared.master')

@section('content')
<div class="container-fluid">
    <div class="row">
        <div class="col-lg-12">
            {{ Form::open(array('url' => '#')) }}
            <ol class="breadcrumb layout-title">
                <li><a href="{{url('usergroup')}}">User Group</a></li>
                <li class="active" ><i class="fa fa-user fa-fw"></i> Input</li>
            </ol>
                {{PageData::Error()}}
            <div class="row">
                <div class="col-lg-6">
                    <div class="form-group">
                        {{Form::label('name','Name *')}}
                        {{Form::hidden('id',$Model->getId(),array('class'=>'form-control'))}}
                        {{Form::text('name',$Model->getName(),array('class'=>'form-control'))}}
                    </div>
                    <div class="form-group">
                        {{Form::label('is_enabled','Is Enabled')}}
                        {{Form::select('is_enabled', $IsEnabledCombo, $Model->getIsEnabled(),array('class'=>'form-control'))}}
                    </div>
                    <div class="form-group">
                        {{Form::label('description','Description')}}
                        {{Form::textarea('description',$Model->getDescription(),array('class'=>'form-control'))}}
                    </div>
                </div>    
            </div>    

            <div class="panel panel-default">
                <div class="panel-heading">
                  <h3 class="panel-title">Privilege Info</h3>
                </div>
                <table class="table table-striped table-bordered table-hover" id="tblDataUser">
                    <thead>
                        <tr>
                            <th>Functions</th>
                            <th>Is Allow Access</th>
                            <th width="36px"></th>
                        </tr>
                    </thead>
                </table>
                <div class="panel-footer">
                <button onClick="addRowTable('tblDataUser',null);" type="button" class="btn btn-primary">Add Row</button>
                </div>
            </div>
            <script>
                var input_table = new Array(); 
		function addRowData(data, table_id) { 
                    input_table[table_id].addRow(data, true, '../../public/images/delete.png'); 
		} 

		function removeRow(id, table_id) { 
                    input_table[table_id].removeRow(id); 
		} 
		
		function addRowTable(table_id, obj_data) { 
                    eval('addRow' + table_id + '(table_id, obj_data);'); 
		} 

                input_table['tblDataUser'] = new azTable('tblDataUser'); 
		var cnttblDataUser = 0; 
                
                <?php 
                    $comboFunction = '<select class="form-control" id="functionId\' + cnttblDataUser + \'" name="functionId[]">';
                    foreach($FunctionsCombo as $key=>$item){
                                $comboFunction .= '<option value="'.$key.'">'.$item.'</option>';
                            }
                    $comboFunction .= '</select>';
                    
                    $comboIsAllowAccess = '<select class="form-control" id="isAllowAccess\' + cnttblDataUser + \'" name="isAllowAccess[]">';
                            foreach($IsAllowAccessCombo as $key=>$item){
                                $comboIsAllowAccess .= '<option value="'.$key.'">'.$item.'</option>';
                            }
                    $comboIsAllowAccess .= '</select>';
                ?>
                    
                    
                    
                function addRowtblDataUser(table_id, obj_data) { 
                    if(obj_data == null) { 
                            obj_data = {
                                Id: '',
                                groupId: '',
                                functionId: '',
                                functionName: '',
                                moduleId: '',
                                moduleName: '',
                                isAllowAccess: true
                            } 

                    } 
			
                    val_Id = (obj_data.Id == undefined) ? '' : obj_data.Id;
                    val_groupId = (obj_data.groupId == undefined) ? '' : obj_data.groupId;
                    val_functionId = (obj_data.functionId == undefined) ? '' : obj_data.functionId;
                    val_functionName = (obj_data.functionName == undefined) ? '' : obj_data.functionName;
                    val_moduleId = (obj_data.moduleId == undefined) ? '' : obj_data.moduleId;
                    val_moduleName = (obj_data.moduleName == undefined) ? '' : obj_data.moduleName;
                    if (obj_data.isAllowAccess == undefined){ 
                        val_isAllowAccess = ''; 
                        val_txtisAllowAccess = ''; 
                    }
                    else{ 
                        val_isAllowAccess = obj_data.isAllowAccess;
                        val_txtisAllowAccess = obj_data.isAllowAccess == true ? 'TRUE' : 'FALSE';
                    }
                    cnttblDataUser++; 
                    
                    addRowData([ 
                        "<input type='hidden' id='privilegeInfo_" + cnttblDataUser + "' name='privilegeInfo[]'  value='" + cnttblDataUser  + "' />" +
                        "<input type='hidden' id='privilegeInfoId_" + cnttblDataUser + "' name='privilegeInfoId[]'  value='" + val_Id  + "' />" +
                        "<input type='hidden' id='usergroupId_" + cnttblDataUser + "' name='userGroupId[]' value='" + val_groupId + "'>" +
                        '{{$comboFunction}}',
                        '{{$comboIsAllowAccess}}'
                        ], 
                    table_id); 
                    selectDefaultCombo('functionId' + cnttblDataUser , val_functionId);
                    selectDefaultCombo('isAllowAccess' + cnttblDataUser , val_isAllowAccess);
                } 	
                
                @foreach ($Model->getPrivilegeInfo() as $item)
                obj_data = {
                    Id: '{{$item->getId()}}',
                    groupId: '{{$item->getGroup()!=null ? $item->getGroup()->getId() : "-"}}',
                    functionId: '{{$item->getFunctions()!=null ? $item->getFunctions()->getId() : "-"}}',
                    functionName: '{{$item->getFunctions()!=null ? $item->getFunctions()->getName() : "-"}}',
                    moduleId: '{{$item->getModule()!=null ? $item->getModule()->getId() : "-"}}',
                    moduleName: '{{$item->getModule()!=null ? $item->getModule()->getName() : "-"}}',
                    isAllowAccess: {{$item->getIsAllowAccess()}}
                } 
                addRowTable('tblDataUser',obj_data);
                @endforeach
            </script>
            
            <p>
                {{Form::submit('Save',array('class'=>'btn btn-primary',"name"=>"submit"))}}
                {{Form::button('Close',array('class'=>'btn btn-primary','onClick'=>"location.href='".url('usergroup')."'"))}}
            </p>

            {{ Form::close() }}
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
</div>
<!-- /.container-fluid -->
    <script>
    
    </script>
@stop